var wotHub = 'http://'+document.domain;

	if (document.domain == 'localhost') {
		wotHub = 'http://'+document.domain+'/wothub';
	}

	window.onload = function() {
		attachModal();
		detachMenu();
	}
	window.onresize = function() {
		detachMenu();
	}
	
function tempo() {
	var tempo = document.getElementById('tempo');
	
	if (tempo == null) {
		var tempo = document.createElement('div');
		var container = document.createElement('div');
		var loading = document.createElement('img');
		loading.src = wotHub+'/smartbok/images/App_Wait2.gif';
		tempo.id = 'tempo';
		tempo.style.height = document.getElementsByTagName('BODY')[0].offsetHeight;
		container.appendChild(loading);
		tempo.appendChild(container);
		document.getElementsByTagName('BODY')[0].appendChild(tempo)
	}
	else {
		if (tempo.style.display == '') {
			tempo.style.display = 'none';
		}
		else {
			tempo.style.display = '';
		}
	}
}

function construireBoiteModale(titreBoite) {
	var wotHub = 'http://'+document.domain;

	if (document.domain == 'localhost') {
		wotHub = 'http://'+document.domain+'/wothub';
	}
	var container = document.createElement('div');
	container.className = "boiteModale";
	container.id = 'tempDiv';
	var titre = document.createElement('h2');
	var fermer = document.createElement('img');
	fermer.src = wotHub+'/images/Delete.png'; 
	fermer.addEventListener('click', function(event) {destroyModal()})
	titre.textContent = titreBoite;
	container.appendChild(titre);
	titre.appendChild(fermer);
	var content = document.createElement('div');
	container.appendChild(content);
	//content.appendChild(fermer);
	return container;
}

function destroyModal() {
	document.getElementsByTagName('BODY')[0].removeChild(document.getElementById('tempDiv'));
}

function attachModal() {
	var isModal = document.getElementById('addRessourceLink');
	if (isModal != null) {
		isModal.addEventListener('click', function(event) {
			document.getElementById('addRessource').style.display = 'block';
		}, false);
			document.getElementsByTagName('form')[0].addEventListener('reset', function(event) {
				document.getElementById('addRessource').style.display = 'none';
			}, false)
	}
}

function getMethode() {
	var queryString = document.URL.substr(wotHub.length+1);
	var params = queryString.split('/');
	var methode = params[1];
	return methode;
}

function getConstructeur() {
	var queryString = document.URL.substr(wotHub.length+1);
	var params = queryString.split('/');
	var classe = params[0];
	return classe;
}

function getParam(indice) {
	var queryString = document.URL.substr(wotHub.length+1);
	var params = queryString.split('/');
	var param = params[indice];
	return param;
}

function execScriptServeur(fonctionAppelee, cible){
	tempo();
	var xhr=null;
	var wotHub = 'http://'+document.domain;

	if (document.domain == 'localhost') {
		wotHub = 'http://'+document.domain+'/wothub';
	}
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { fonctionAppelee(xhr); };
 
    //on appelle le fichier reponse.txt
    xhr.open("GET", wotHub+cible);
    //xhr.open("GET", "../test.php");
    xhr.send(null);
}

function in_array(needle, haystack) {
	for(n = 0; n < haystack.length; n++) {
		if (haystack[n] == needle) {
			return true;
		}
	}
	return false;
}

function detachMenu() {
	var nav = document.getElementById('navigation');
	if (window.innerWidth < 900) {
		nav.className = "nav_petit";
	}
	else {
		nav.className = '';
	}
}